<!DOCTYPE HTML>
<html>
<head>
    @include('common.header')
    <title>添加管理员</title>
</head>
<body>
<div class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-article-category">
        <input type="hidden" name="id" value="{{$info['id']}}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户名：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{{$info['username']}}" placeholder="" id="" name="username">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>密码：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{{$info['password']}}" placeholder="" id="" name="password">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账户状态：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="radio" name="status" id="" value="0" class="radio" <?php if(!isset($info['status']) || $info['status']==0): ?>checked<?php endif; ?> />&nbsp;&nbsp;无效
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="status" id="" value="1" class="radio" <?php if(isset($info['status']) && $info['status']==1): ?>checked<?php endif; ?> />&nbsp;&nbsp;有效
            </div>
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-2">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;" onclick="return false;">
            </div>
        </div>
    </form>
</div>
@include('common.footer')

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="{{asset('hui-admin/lib/jquery.validation/1.14.0/jquery.validate.js')}}"></script>
<script type="text/javascript" src="{{asset('hui-admin/lib/jquery.validation/1.14.0/validate-methods.js')}}"></script>
<script type="text/javascript" src="{{asset('hui-admin/lib/jquery.validation/1.14.0/messages_zh.js')}}"></script>
<script type="text/javascript">
    $('input[type=submit]').click(function () {
        _id = $('input[name=id]').val();
        _username = $('input[name=username]').val();
        _password = $('input[name=password]').val();
        _status = $('input[name=status]:checked').val();
        if(isNull(_username) || isNull(_password)){
            layer.msg('请勿留空');
            return false;
        }
        _json_data = {'id':_id,'username':_username,'password':_password,'status':_status};
        $.ajax({
            type:'post',
            url:'/Admin/edit.html',
            data:_json_data,
            dataType:'json',
            success:function(data){
                if(data.code == 1) {
                    var FrameIndex = parent.layer.getFrameIndex(window.name);
                    parent.refresh();
                    parent.layer.close(FrameIndex);
                }else{
                    layer.msg(data.msg);
                }
            }
        });
        return false;
    });


    var uploading = false;
    $("#upload_logo").on("change", function(){
        if(uploading){
            alert("文件正在上传中，请稍候");
            return false;
        }
        $.ajax({
            url: "/ArticleCategory/uploadImg",
            type: 'POST',
            cache: false,
            data: new FormData($('#form-article-category')[0]),
            processData: false,
            contentType: false,
            dataType:"json",
            beforeSend: function(){
                uploading = true;
            },
            success : function(data) {
                if (data.code == 1) {
                    if($("#logo").length > 0) {
                        //元素存在时执行的代码
                        $("#logo").attr("src", data.img_url);
                    }else{
                        $("#upload_logo").after("<div><img id='logo' width='90' height='90' src='"+data.img_url+"'></div>");
                    }
                } else {
                    showError(data.msg);
                }
                uploading = false;
            }
        });
    });
</script>
</body>
</html>